package com.tank.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

import org.directwebremoting.annotations.DataTransferObject;
import org.directwebremoting.annotations.Param;
import org.hibernate.annotations.GenericGenerator;

import com.tank.bean.item.Item;
import com.tank.util.Gender;

@DataTransferObject(params = @Param(name = "include", value = "id,name,mail,photo,home,school,intro"))  
@Entity
public class User implements Serializable {
	private static final long serialVersionUID = 1L;
	
	@GenericGenerator(name = "gen", strategy = "increment")
	@Id
	@GeneratedValue(generator = "gen")
	private Integer id;
	
	
	@Column(length=60)
	private String name;//用户名
	@Column(length=60)
	private String mail;//邮箱
	@Column(length=60)
	private String pass;//密码
	
	private Boolean valid;//邮箱是否验证
	
	private Integer credit;//要配置一个每个 等级  的饱合 信誉
	private Integer grade;//字典 等级 ，称号《-等级
	
	@ManyToMany
	@JoinTable(name="buddy",
	joinColumns={@JoinColumn(name="fid",referencedColumnName="id")},
	inverseJoinColumns={@JoinColumn(name="tid",referencedColumnName="id")}
			)
	private List<User> follows=new ArrayList<User>(0);//我关注的人
	@ManyToMany(mappedBy="follows")
	private List<User> fans=new ArrayList<User>(0);//关注我的人
	
	@ManyToMany(mappedBy="atUsers")
	private List<Item> atItems=new ArrayList<Item>(0);//关注我的人
	
	
	private Integer fanCount;
	private Integer followCount;
	private Integer itemCount;
	private Integer talkCount;
	private Integer wantCount;
	
	
	
	
	@Column(length=100)
	private String photo;//头像
	
	
	@Enumerated(EnumType.ORDINAL)
	private Gender gender;//性别
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="schood_id")
	private School school;
	
	private String home;//居住地
	
	@OneToOne(mappedBy="author",fetch=FetchType.LAZY)
	private Yard yard;//院子
	
	
	@Column(length=100)
	private String intro;//介绍
	
	
	public User(){}
	public User(Integer id	){this.id= id;}
	
	public User(String name, String pass){
		this.name=name;
		this.pass=pass;
	}
	
	
	
	
	@Override
	public String toString() {
		StringBuilder sb=new StringBuilder();
		sb.append("{");
		sb.append("id：").append(this.getId());
		sb.append("用户名：").append(this.getName());
		sb.append("密码：").append(this.getPass());
		sb.append("}");
		return sb.toString();
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getMail() {
		return mail;
	}
	public void setMail(String mail) {
		this.mail = mail;
	}
	public String getPass() {
		return pass;
	}
	public void setPass(String pass) {
		this.pass = pass;
	}
	public Integer getCredit() {
		return credit;
	}
	public void setCredit(Integer credit) {
		this.credit = credit;
	}
	public Integer getGrade() {
		return grade;
	}
	public void setGrade(Integer grade) {
		this.grade = grade;
	}
	public List<User> getFollows() {
		return follows;
	}
	public void setFollows(List<User> follows) {
		this.follows = follows;
	}
	public List<User> getFans() {
		return fans;
	}
	public void setFans(List<User> fans) {
		this.fans = fans;
	}
	public Integer getFanCount() {
		return fanCount;
	}
	public void setFanCount(Integer fanCount) {
		this.fanCount = fanCount;
	}
	public Integer getFollowCount() {
		return followCount;
	}
	public void setFollowCount(Integer followCount) {
		this.followCount = followCount;
	}
	public Integer getItemCount() {
		return itemCount;
	}
	public void setItemCount(Integer itemCount) {
		this.itemCount = itemCount;
	}
	public Integer getTalkCount() {
		return talkCount;
	}
	public void setTalkCount(Integer talkCount) {
		this.talkCount = talkCount;
	}
	public Integer getWantCount() {
		return wantCount;
	}
	public void setWantCount(Integer wantCount) {
		this.wantCount = wantCount;
	}
	public String getPhoto() {
		return photo;
	}
	public void setPhoto(String photo) {
		this.photo = photo;
	}
	public Gender getGender() {
		return gender;
	}
	public void setGender(Gender gender) {
		this.gender = gender;
	}
	public School getSchool() {
		return school;
	}
	public void setSchool(School school) {
		this.school = school;
	}
	public String getHome() {
		return home;
	}
	public void setHome(String home) {
		this.home = home;
	}
	public Yard getYard() {
		return yard;
	}
	public void setYard(Yard yard) {
		this.yard = yard;
	}
	public String getIntro() {
		return intro;
	}
	public void setIntro(String intro) {
		this.intro = intro;
	}
	
	public Boolean getValid() {
		return valid;
	}
	public void setValid(Boolean valid) {
		this.valid = valid;
	}
	public List<Item> getAtItems() {
		return atItems;
	}
	public void setAtItems(List<Item> atItems) {
		this.atItems = atItems;
	}
	
	
	
	
	
	
	
	
}
